﻿using System.Windows.Input;
using System.Windows;

namespace MDCAdminTool.Commands
{
	public class ImportConfigCacheCluster : AsyncCommandBindingBase
	{
		public ImportConfigCacheCluster()
			: base()
		{
			Command = Application.Current.Resources["ImportConfigCacheCluster"] as ICommand;
		}

		protected override void OnExecuted(object sender, ExecutedRoutedEventArgs e)
		{
			var cluster = e.Parameter as CacheCluster;
			if (cluster == null)
			{
				var @base = e.Parameter as GroupBase;
				if (@base != null)
				{
					cluster = @base.Cluster;
				}
				else
				{
					return;
				}
			}

			var dlg = new Microsoft.Win32.OpenFileDialog
			{
				DefaultExt = ".config",
				Filter = "Config files (.config)|*.config"
			};

			if (dlg.ShowDialog() ?? false)
			{
				cluster.ImportConfigFile = dlg.FileName;
				cluster.ImportConfig();
			}
		}
	}

}
